home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Night Owl 6
/
Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso
/
029a
/
qbtree51.zip
/
DEMOQBT.BAS
next >
Wrap
BASIC Source File
|
1991-04-07
|
34KB
|
1,234 lines
DECLARE SUB DoDeleteReadII ()
DECLARE SUB DoAddReadII ()
DECLARE SUB DoCreateOpenII ()
DECLARE SUB DoCloseII ()
DECLARE SUB DoDeleteReadI ()
DECLARE SUB DoStoreReadI ()
DECLARE SUB DoCloseI ()
DECLARE SUB DoCreateOpenI ()
DECLARE SUB DoDemo ()
DECLARE SUB DoInitQBTREE ()
DECLARE SUB ClearMsgArea ()
DECLARE SUB ShowErrorMsg (stat%)
DECLARE SUB DoAboutPg9 (row%, col%, rows%, cols%)
DECLARE SUB DoAboutPg8 (row%, col%, rows%, cols%)
DECLARE SUB DoAboutPg7 (row%, col%, rows%, cols%)
DECLARE SUB DoAboutPg6 (row%, col%, rows%, cols%)
DECLARE SUB DoAboutPg5 (row%, col%, rows%, cols%)
DECLARE SUB DoAboutPg4 (row%, col%, rows%, cols%)
DECLARE SUB DoAboutPg3 (row%, col%, rows%, cols%)
DECLARE SUB DoAboutPg2 (row%, col%, rows%, cols%)
DECLARE SUB DoAboutPg1 (row%, col%, rows%, cols%)
DECLARE SUB DoAboutPg0 (row%, col%, rows%, cols%)
DECLARE SUB DoAboutPages ()
DECLARE SUB DelaySec (sec%)
DECLARE SUB ShowMessage (msg$)
DECLARE SUB GetWindow (row%, col%, rows%, cols%)
DECLARE SUB PutWindow (row%, col%)
DECLARE SUB ScrollWindow (row%, col%, rows%, cols%, dir%, lines%)
DECLARE SUB DoTitleScreen ()
DECLARE SUB MakeWindow (row%, col%, rows%, cols%, bg%)
DECLARE FUNCTION Center% (strg$, col%, cols%)
DECLARE FUNCTION SignalMessage% (msg$, waitfor%)
DECLARE FUNCTION GetKey% (waitfor%)
DEFINT A-Z
TYPE RegTypex
ax AS INTEGER
bx AS INTEGER
cx AS INTEGER
dx AS INTEGER
bp AS INTEGER
si AS INTEGER
di AS INTEGER
flags AS INTEGER
ds AS INTEGER
es AS INTEGER
END TYPE '20
REM $INCLUDE: 'qbtree50.bi'
DIM SHARED iregx AS RegTypex, oregx AS RegTypex
DIM SHARED VideoSeg AS INTEGER
DIM SHARED keyin AS INTEGER
DIM SHARED MaxKeys AS INTEGER '{keys to create...}
DIM SHARED TestI AS INTEGER '{do demo I if <> 0}
DIM SHARED TestII AS INTEGER '{do demo II if <> 0}
DECLARE SUB VECTORX (intnum%, iregx AS RegTypex, oregx AS RegTypex)
REDIM SHARED WinBuff(0 TO 80 * 25) AS INTEGER
MaxKeys = 500
TestI = -1
TestII = -1
cmd$ = COMMAND$
mx = INSTR(cmd$, "/K=")
m1 = INSTR(cmd$, "/1=")
m2 = INSTR(cmd$, "/2=")
IF mx THEN MaxKeys = VAL(MID$(cmd$, mx + 3, 7))
IF m1 THEN TestI = MID$(cmd$, m1 + 3, 1) <> "0"
IF m2 THEN TestII = MID$(cmd$, m2 + 3, 1) <> "0"
IF INSTR(cmd$, "?") THEN
PRINT
PRINT "DEMOQBT - a demonstration of QBTREE 5.0"
PRINT
PRINT CHR$(9); "/K=nnnnn number of keys to use in the tests (default=500)"
PRINT CHR$(9); "/1=0 skip test I (default=don't skip)"
PRINT CHR$(9); "/2=0 skip test II (default=don't skip)"
PRINT
SYSTEM
END IF
DoTitleScreen
DoAboutPages
IF keyin <> 27 THEN DoDemo
COLOR 7, 0: LOCATE 25, 1: PRINT SPACE$(80);
LOCATE 24, 1
SYSTEM
FUNCTION Center (strg$, col, cols)
'return the required column start for the string to be centered
'between column (col) to column (col+cols-1)
length = LEN(strg$)
tc = col + (cols \ 2) - (length \ 2)
IF tc > (80 - length) THEN tc = 80 - length
IF tc < 1 THEN tc = 1
Center = tc
END FUNCTION
SUB ClearMsgArea
COLOR 0, 0
LOCATE 24, 22
PRINT SPACE$(59);
LOCATE 25, 22
PRINT SPACE$(59);
COLOR 15, 0
END SUB
SUB DelaySec (sec)
'EXIT SUB
'wait for sec seconds
'sec must be <= 60
'the current time and the (current time+sec) should not span
'MIDNIGHT else the routine exits without waiting
IF sec > 60 THEN EXIT SUB
iregx.ax = &H2C00
VECTORX &H21, iregx, oregx
cursec = oregx.dx \ 256
curmin = oregx.cx AND 255
curhr = oregx.cx \ 256
wait2hr = curhr
wait2min = curmin
wait2sec = cursec + sec
IF wait2sec > 59 THEN
wait2min = curmin + 1
wait2sec = wait2sec - 60
IF wait2min > 59 THEN
wait2hr = curhr + 1
wait2min = wait2min - 60
IF wait2hr > 23 THEN nowait = -1
END IF
END IF
IF NOT nowait THEN
cmptime& = (10000& * wait2hr) + (wait2min * 100) + wait2sec
DO
VECTORX &H21, iregx, oregx
curtime& = 10000& * (oregx.cx \ 256) + (oregx.cx AND 255) * 100 + (oregx.dx \ 256)
LOOP UNTIL curtime& >= cmptime&
END IF
END SUB
SUB DoAboutPages
COLOR 15, 5: LOCATE 5, 2: PRINT CHR$(16)
row = 2: col = 4: rows = 21: cols = 74
GetWindow row, col, rows, cols
page2do = 0
DO
SELECT CASE page2do
CASE 0
DoAboutPg0 row, col, rows, cols
GOSUB What2Do
CASE 1
DoAboutPg1 row, col, rows, cols
GOSUB What2Do
CASE 2
DoAboutPg2 row, col, rows, cols
GOSUB What2Do
CASE 3
DoAboutPg3 row, col, rows, cols
GOSUB What2Do
CASE 4
DoAboutPg4 row, col, rows, cols
GOSUB What2Do
CASE 5
DoAboutPg5 row, col, rows, cols
GOSUB What2Do
CASE 6
DoAboutPg6 row, col, rows, cols
GOSUB What2Do
CASE 7
DoAboutPg7 row, col, rows, cols
GOSUB What2Do
CASE 8
DoAboutPg8 row, col, rows, cols
GOSUB What2Do
CASE 9
DoAboutPg9 row, col, rows, cols
GOSUB What2Do
CASE ELSE
END SELECT
LOOP UNTIL keyin = 27 OR keyin = 66
PutWindow row, col
COLOR 15, 5: LOCATE 5, 2: PRINT CHR$(251)
EXIT SUB
What2Do:
SELECT CASE keyin
CASE &H30 TO &H39
page2do = keyin - &H30
CASE 1072, 1073
page2do = page2do - 1
IF page2do < 0 THEN page2do = 9
CASE 1080, 1081
page2do = page2do + 1
IF page2do = 10 THEN page2do = 0
CASE 1071
page2do = 0
CASE 1079
page2do = 9
CASE IS <> 27
page2do = page2do + 1
IF page2do = 10 THEN page2do = 0
CASE ELSE
END SELECT
IF keyin = 27 AND page2do <> 0 THEN
page2do = 0
keyin = 255
END IF
RETURN
END SUB
SUB DoAboutPg0 (row, col, rows, cols)
'page 0 about info
MakeWindow row, col, rows, cols, 7
MakeWindow row + 1, col + 1, rows - 2, cols - 2, 0
COLOR 15, 0
title$ = "QBTREE 5.00"
LOCATE row + 2, Center(title$, col, cols): PRINT title$
title$ = "A FILE ACCESS METHOD FOR QB/PDS PROGRAMMERS"
LOCATE , Center(title$, col, cols): PRINT title$
PRINT
LOCATE , col + 29: PRINT "Table of Contents"
COLOR 2, 0
LOCATE , col + 29: PRINT STRING$(17, 196)
COLOR 15, 0
PRINT
LOCATE , col + 5: PRINT "1. Technical Specifications"
LOCATE , col + 5: PRINT "2. Initializing QBTREE and Creating Files"
LOCATE , col + 5: PRINT "3. Opening, Closing and Flushing Files"
LOCATE , col + 5: PRINT "4. Get Information About Key and Data Files"
LOCATE , col + 5: PRINT "5. Adding to Key and Data Files"
LOCATE , col + 5: PRINT "6. Getting from Key and Data Files"
LOCATE , col + 5: PRINT "7. Storing and Retrieving from Key Files (Index-Only Manager)"
LOCATE , col + 5: PRINT "8. Deleting from Key and Data Files"
LOCATE , col + 5: PRINT "9. Network Support Routines"
PRINT
LOCATE , col + 8: PRINT "Press a number above, B to begin the demo, or Esc to quit"
COLOR 0, 7
LOCATE row + rows - 1, col + cols - 9: PRINT "more...";
keyin = GetKey(1)
END SUB
SUB DoAboutPg1 (row, col, rows, cols)
'page 1 about info
MakeWindow row, col, rows, cols, 7
MakeWindow row + 1, col + 1, rows - 2, cols - 2, 0
COLOR 0, 7
LOCATE row, (col + cols - 8): PRINT "Pg 1/9"
COLOR 15, 0
title$ = "Technical Specifications"
LOCATE row + 2, Center(title$, col, cols): PRINT title$
title$ = STRING$(LEN(title$), 196)
COLOR 2
LOCATE row + 3, Center(title$, col, cols): PRINT title$
COLOR 15, 0
PRINT
LOCATE , col + 4: PRINT "Max keys/keyfile : ";
COLOR 7, 0: PRINT " 5,504,940 keys (65,535 nodes)": COLOR 15, 0
LOCATE , col + 4: PRINT "Max recs/datafile: ";
COLOR 7, 0: PRINT "16,384,000 records": COLOR 15, 0
PRINT
LOCATE , col + 4: PRINT "Max key length : ";
COLOR 7, 0: PRINT " 64 bytes": COLOR 15, 0
LOCATE , col + 4: PRINT "Max rec length : ";
COLOR 7, 0: PRINT "32,767 bytes": COLOR 15, 0
PRINT
LOCATE , col + 4: PRINT "Max open key files : ";
COLOR 7, 0: PRINT "250 files at one time": COLOR 15, 0
LOCATE , col + 4: PRINT "Max open data files: ";
COLOR 7, 0: PRINT "250 files at one time": COLOR 15, 0
PRINT
LOCATE , col + 4: PRINT "Indexing algorithm: ";
COLOR 7, 0: PRINT "proprietary B-TREE, ASCII sort": COLOR 15, 0
PRINT
LOCATE , col + 4: PRINT "Complete specs and file formats are listed in the manual."
COLOR 0, 7
LOCATE row + rows - 1, col + cols - 9: PRINT "more...";
keyin = GetKey(1)
END SUB
SUB DoAboutPg2 (row, col, rows, cols)
'page 2 about info
MakeWindow row, col, rows, cols, 7
MakeWindow row + 1, col + 1, rows - 2, cols - 2, 0
COLOR 0, 7
LOCATE row, (col + cols - 8): PRINT "Pg 2/9"
COLOR 15, 0
title$ = "Initializing QBTREE and Creating Files"
LOCATE row + 2, Center(title$, col, cols): PRINT title$
title$ = STRING$(LEN(title$), 196)
COLOR 2
LOCATE row + 3, Center(title$, col, cols): PRINT title$
COLOR 15, 0
PRINT
LOCATE , col + 4: PRINT "Allocate buffer areas (in far memory at runtime) and setup extended"
LOCATE , col + 4: PRINT "file table to allow for up to 250 files to be opened at once. Also,"
LOCATE , col + 4: PRINT "close all QBTREE files and release allocated memory."
COLOR 7, 0
PRINT
LOCATE , col + 7: PRINT "status = InitQBTREE(MaxKeyFiles,MaxDataFiles)"
LOCATE , col + 7: PRINT "status = ExitQBTREE()"
COLOR 15, 0
PRINT
LOCATE , col + 4: PRINT "Create new key and data files."
COLOR 7, 0
PRINT
LOCATE , col + 7: PRINT "status = CreateDataFile(pathname$,recordlength)"
LOCATE , col + 7: PRINT "status = CreateKeyFile(pathname$,keylength)"
COLOR 0, 7
LOCATE row + rows - 1, col + cols - 9: PRINT "more...";
keyin = GetKey(1)
END SUB
SUB DoAboutPg3 (row, col, rows, cols)
'page 3 about info
MakeWindow row, col, rows, cols, 7
MakeWindow row + 1, col + 1, rows - 2, cols - 2, 0
COLOR 0, 7
LOCATE row, (col + cols - 8): PRINT "Pg 3/9"
COLOR 15, 0
title$ = "Opening, Closing and Flushing Files"
LOCATE row + 2, Center(title$, col, cols): PRINT title$
title$ = STRING$(LEN(title$), 196)
COLOR 2
LOCATE row + 3, Center(title$, col, cols): PRINT title$
COLOR 15, 0
PRINT
LOCATE , col + 4: PRINT "Open and close QBTREE files."
COLOR 7, 0
PRINT
LOCATE , col + 7: PRINT "status = OpenDataFile(pathname$,dfileno)"
LOCATE , col + 7: PRINT "status = OpenKeyFile(pathname$,kfileno)"
LOCATE , col + 7: PRINT "status = CloseDataFile(dfileno)"
LOCATE , col + 7: PRINT "status = CloseKeyFile(kfileno)"
COLOR 15, 0
PRINT
LOCATE , col + 4: PRINT "Physically write buffered data to disk and update the directory"
LOCATE , col + 4: PRINT "entry without having to close and then reopen the files."
COLOR 7, 0
PRINT
LOCATE , col + 7: PRINT "status = FlushDataFile(dfileno,dup)"
LOCATE , col + 7: PRINT "status = FlushKeyFile(kfileno,dup)"
PRINT
COLOR 0, 7
LOCATE row + rows - 1, col + cols - 9: PRINT "more...";
keyin = GetKey(1)
END SUB
SUB DoAboutPg4 (row, col, rows, cols)
'page 4 about info
MakeWindow row, col, rows, cols, 7
MakeWindow row + 1, col + 1, rows - 2, cols - 2, 0
COLOR 0, 7
LOCATE row, (col + cols - 8): PRINT "Pg 4/9"
COLOR 15, 0
title$ = "Get Information About Key and Data Files"
LOCATE row + 2, Center(title$, col, cols): PRINT title$
title$ = STRING$(LEN(title$), 196)
COLOR 2
LOCATE row + 3, Center(title$, col, cols): PRINT title$
COLOR 15, 0
PRINT
LOCATE , col + 4: PRINT "Get information on an opened QBTREE file including the record or"
LOCATE , col + 4: PRINT "key length, the number of records or keys in a file, and the BASIC"
LOCATE , col + 4: PRINT "file number being used to access that file."
COLOR 7, 0
PRINT
LOCATE , col + 7: PRINT "status = StatDataFile(dfileno,reclength,recs&,bfileno)"
LOCATE , col + 7: PRINT "status = StatKeyFile(kfileno,keylength,keys&,bfileno)"
COLOR 15, 0
PRINT
LOCATE , col + 4: PRINT "Get the last found key's data record pointer (record number)."
COLOR 7, 0
PRINT
LOCATE , col + 7: PRINT "status = GetPosition(kfileno,recno&)"
COLOR 0, 7
LOCATE row + rows - 1, col + cols - 9: PRINT "more...";
keyin = GetKey(1)
END SUB
SUB DoAboutPg5 (row, col, rows, cols)
'page 5 about info
MakeWindow row, col, rows, cols, 7
MakeWindow row + 1, col + 1, rows - 2, cols - 2, 0
COLOR 0, 7
LOCATE row, (col + cols - 8): PRINT "Pg 5/9"
COLOR 15, 0
title$ = "Adding to Key and Data Files"
LOCATE row + 2, Center(title$, col, cols): PRINT title$
title$ = STRING$(LEN(title$), 196)
COLOR 2
LOCATE row + 3, Center(title$, col, cols): PRINT title$
COLOR 15, 0
PRINT
LOCATE , col + 4: PRINT "Add (insert) a new key and data record to the key and data files."
LOCATE , col + 4: PRINT "Also, add a key to a keyfile using the currently active data record"
LOCATE , col + 4: PRINT "as its data pointer (record number)."
COLOR 7, 0
PRINT
LOCATE , col + 7: PRINT "status = AddKeyRecord(kfile,dfile,Qkey$,Qrec$)"
LOCATE , col + 7: PRINT "status = AddKey(kfile,dfile,Qkey$)"
COLOR 15, 0
PRINT
LOCATE , col + 4: PRINT "Update the currently active data record."
COLOR 7, 0
PRINT
LOCATE , col + 7: PRINT "status = UpdateRecord(dfile,Qrec$)"
COLOR 0, 7
LOCATE row + rows - 1, col + cols - 9: PRINT "more...";
keyin = GetKey(1)
END SUB
SUB DoAboutPg6 (row, col, rows, cols)
'page 6 about info
MakeWindow row, col, rows, cols, 7
MakeWindow row + 1, col + 1, rows - 2, cols - 2, 0
COLOR 0, 7
LOCATE row, (col + cols - 8): PRINT "Pg 6/9"
COLOR 15, 0
title$ = "Getting from Key and Data Files"
LOCATE row + 2, Center(title$, col, cols): PRINT title$
title$ = STRING$(LEN(title$), 196)
COLOR 2
LOCATE row + 3, Center(title$, col, cols): PRINT title$
COLOR 15, 0
PRINT
LOCATE , col + 4: PRINT "Get the key equal to Qkey$ (or if not found the one following) and"
LOCATE , col + 4: PRINT "return its data record, or, having already found a key, get either"
LOCATE , col + 4: PRINT "the previous or next and return its key and data record. Also, get"
LOCATE , col + 4: PRINT "the very first or very last key and data record."
COLOR 7, 0
PRINT
LOCATE , col + 7: PRINT "status = GetEqual(kfile,dfile,Qkey$,Qrec$)"
LOCATE , col + 7: PRINT "status = GetPrev(kfile,dfile,Qkey$,Qrec$)"
LOCATE , col + 7: PRINT "status = GetNext(kfile,dfile,Qkey$,Qrec$)"
LOCATE , col + 7: PRINT "status = GetFirst(kfile,dfile,Qkey$,Qrec$)"
LOCATE , col + 7: PRINT "status = GetLast(kfile,dfile,Qkey$,Qrec$)"
COLOR 15, 0
PRINT
LOCATE , col + 4: PRINT "Access a data record directly by record number."
COLOR 7, 0
PRINT
LOCATE , col + 7: PRINT "status = GetDirect(dfileno,drecno&,Qrec$)"
COLOR 0, 7
LOCATE row + rows - 1, col + cols - 9: PRINT "more...";
keyin = GetKey(1)
END SUB
SUB DoAboutPg7 (row, col, rows, cols)
'page 7 about info
MakeWindow row, col, rows, cols, 7
MakeWindow row + 1, col + 1, rows - 2, cols - 2, 0
COLOR 0, 7
LOCATE row, (col + cols - 8): PRINT "Pg 7/9"
COLOR 15, 0
title$ = "Storing and Retrieving from Key Files (Index-Only Manager)"
LOCATE row + 2, Center(title$, col, cols): PRINT title$
title$ = STRING$(LEN(title$), 196)
COLOR 2
LOCATE row + 3, Center(title$, col, cols): PRINT title$
COLOR 15, 0
PRINT
LOCATE , col + 4: PRINT "Store the key and record number in kfile."
COLOR 7, 0
PRINT
LOCATE , col + 7: PRINT "status = StoreKey(kfile,Qkey$,Qurecno&)"
COLOR 15, 0
PRINT
LOCATE , col + 4: PRINT "Get the key equal to Qkey$ (or if not found the one following) and"
LOCATE , col + 4: PRINT "return its record number, or, having already found a key, get either"
LOCATE , col + 4: PRINT "the previous or next and return its key and record number. Also, get"
LOCATE , col + 4: PRINT "the very first or very last key and record number."
COLOR 7, 0
PRINT
LOCATE , col + 7: PRINT "status = RetrieveEqual(kfile,Qkey$,Qurecno&)"
LOCATE , col + 7: PRINT "status = RetrievePrev(kfile,Qkey$,Qurecno&)"
LOCATE , col + 7: PRINT "status = RetrieveNext(kfile,Qkey$,Qurecno&)"
LOCATE , col + 7: PRINT "status = RetrieveFirst(kfile,Qkey$,Qurecno&)"
LOCATE , col + 7: PRINT "status = RetrieveLast(kfile,Qkey$,Qurecno&)"
COLOR 0, 7
LOCATE row + rows - 1, col + cols - 9: PRINT "more...";
keyin = GetKey(1)
END SUB
SUB DoAboutPg8 (row, col, rows, cols)
'page 8 about info
MakeWindow row, col, rows, cols, 7
MakeWindow row + 1, col + 1, rows - 2, cols - 2, 0
COLOR 0, 7
LOCATE row, (col + cols - 8): PRINT "Pg 8/9"
COLOR 15, 0
title$ = "Deleting from Key and Data Files"
LOCATE row + 2, Center(title$, col, cols): PRINT title$
title$ = STRING$(LEN(title$), 196)
COLOR 2
LOCATE row + 3, Center(title$, col, cols): PRINT title$
COLOR 15, 0
PRINT
LOCATE , col + 4: PRINT "Delete the key from the key file."
COLOR 7, 0
PRINT
LOCATE , col + 7: PRINT "status = DeleteKey(kfile,Qkey$)"
COLOR 15, 0
PRINT
LOCATE , col + 4: PRINT "Delete the key from the key file and also the data record that it"
LOCATE , col + 4: PRINT "points to from the data file."
COLOR 7, 0
PRINT
LOCATE , col + 7: PRINT "status = DeleteKeyRecord(kfile,dfile,Qkey$)"
COLOR 0, 7
LOCATE row + rows - 1, col + cols - 9: PRINT "more...";
keyin = GetKey(1)
END SUB
SUB DoAboutPg9 (row, col, rows, cols)
'page 9 about info
MakeWindow row, col, rows, cols, 7
MakeWindow row + 1, col + 1, rows - 2, cols - 2, 0
COLOR 0, 7
LOCATE row, (col + cols - 8): PRINT "Pg 9/9"
COLOR 15, 0
title$ = "Network Support Routines"
LOCATE row + 2, Center(title$, col, cols): PRINT title$
title$ = STRING$(LEN(title$), 196)
COLOR 2
LOCATE row + 3, Center(title$, col, cols): PRINT title$
COLOR 15, 0
PRINT
LOCATE , col + 4: PRINT "Load key and data file headers."
LOCATE , col + 4: PRINT "Lock and unlock key and data files and records."
COLOR 7, 0
PRINT
LOCATE , col + 7: PRINT "stat = LoadDataHeader(dfile)"
LOCATE , col + 7: PRINT "stat = LoadKeyHeader(kfile)"
LOCATE , col + 7: PRINT "stat = LockDataHeader(dfile)"
LOCATE , col + 7: PRINT "stat = LockKeyFile(kfile)"
LOCATE , col + 7: PRINT "stat = LockRecord(dfile,recno&)"
LOCATE , col + 7: PRINT "stat = UnlockDataHeader(dfile)"
LOCATE , col + 7: PRINT "stat = UnlockKeyFile(kfile)"
LOCATE , col + 7: PRINT "stat = UnlockRecord(dfile,recno&)"
COLOR 0, 7
LOCATE row + rows - 1, col + cols - 9: PRINT "more...";
keyin = GetKey(1)
END SUB
SUB DoAddReadII
row = 4: col = 22: rows = 16: cols = 18
COLOR 15, 5: LOCATE 15, 2: PRINT CHR$(16)
ClearMsgArea
LOCATE 24, 22: COLOR 15, 0
PRINT "Adding"; MaxKeys; "rnd 7-byte keys to "; CHR$(34); "KEYONE.II"; CHR$(34); ","; MaxKeys; "rnd 8-";
LOCATE 25, 22
PRINT "byte keys to "; CHR$(34); "KEYTWO.II"; CHR$(34); ","; MaxKeys; "16-byte recs to "; CHR$(34); "DATA.II"; CHR$(34);
cnt = 0
prnrow = 3
COLOR 15, 1
DO
keynum1$ = CHR$(65 + (RND * 25)) + LTRIM$(STR$(INT(RND * 899) + 100)) + LTRIM$(STR$(INT(RND * 899) + 100))
keynum2$ = CHR$(65 + (RND * 25)) + LTRIM$(STR$(INT(RND * 899) + 100)) + LTRIM$(STR$(INT(RND * 899) + 100)) + "*"
Qrec$ = keynum1$ + "-" + keynum2$
stat = AddKeyRecord(0, 0, keynum1$, Qrec$)
IF stat = 0 THEN stat = AddKey(1, 0, keynum2$)
IF stat = 0 THEN
prnrow = prnrow + 1
IF prnrow > 19 THEN
ScrollWindow row, col, rows, cols, 1, 1
ScrollWindow row, col + 20, rows, cols, 1, 1
ScrollWindow row, col + 40, rows, cols, 1, 1
prnrow = 19
END IF
LOCATE prnrow, 23
PRINT keynum1$;
LOCATE prnrow, 43
PRINT keynum2$;
LOCATE prnrow, 63
PRINT Qrec$;
cnt = cnt + 1
ELSEIF stat <> 201 THEN
nul = CloseKeyFile(0)
nul = CloseKeyFile(1)
nul = CloseDataFile(0)
ShowErrorMsg stat
END IF
LOOP UNTIL cnt >= MaxKeys
DelaySec 2
ScrollWindow row, col, rows, cols, 1, 0 '{clear window}
ScrollWindow row, col + 20, rows, cols, 1, 0
ScrollWindow row, col + 40, rows, cols, 1, 0
ClearMsgArea
LOCATE 24, 22: COLOR 15, 0
PRINT "Reading the data records indexed by "; CHR$(34); "KEYONE.II"; CHR$(34);
prnrow = 3
COLOR 15, 1
stat = GetFirst(0, 0, Qkey$, Qrec$)
DO WHILE stat = 0
prnrow = prnrow + 1
IF prnrow > 19 THEN
ScrollWindow row, col, rows, cols, 1, 1
ScrollWindow row, col + 40, rows, cols, 1, 1
prnrow = 19
END IF
LOCATE prnrow, 23
PRINT Qkey$;
LOCATE prnrow, 63
PRINT Qrec$;
stat = GetNext(0, 0, Qkey$, Qrec$)
LOOP
DelaySec 2
ScrollWindow row, col, rows, cols, 1, 0 '{clear window}
ScrollWindow row, col + 40, rows, cols, 1, 0
ClearMsgArea
LOCATE 24, 22: COLOR 15, 0
PRINT "Reading the same data records indexed by "; CHR$(34); "KEYTWO.II"; CHR$(34);
prnrow = 3
COLOR 15, 1
stat = GetFirst(1, 0, Qkey$, Qrec$)
DO WHILE stat = 0
prnrow = prnrow + 1
IF prnrow > 19 THEN
ScrollWindow row, col + 20, rows, cols, 1, 1
ScrollWindow row, col + 40, rows, cols, 1, 1
prnrow = 19
END IF
LOCATE prnrow, 43
PRINT Qkey$;
LOCATE prnrow, 63
PRINT Qrec$;
stat = GetNext(1, 0, Qkey$, Qrec$)
LOOP
DelaySec 2
COLOR 15, 5: LOCATE 15, 2: PRINT CHR$(251)
END SUB
SUB DoCloseI
COLOR 15, 5: LOCATE 13, 2: PRINT CHR$(16)
ClearMsgArea
LOCATE 24, 22: COLOR 15, 0
PRINT "Closing "; CHR$(34); "KEYONE.I"; CHR$(34);
stat = CloseKeyFile(0)
IF stat THEN ShowErrorMsg stat
DelaySec 1
COLOR 15, 5: LOCATE 13, 2: PRINT CHR$(251)
END SUB
SUB DoCloseII
COLOR 15, 5: LOCATE 17, 2: PRINT CHR$(16)
ClearMsgArea
LOCATE 24, 22: COLOR 15, 0
PRINT "Closing "; CHR$(34); "KEYONE.II"; CHR$(34);
stat = CloseKeyFile(0)
IF stat THEN ShowErrorMsg stat
DelaySec 1
ClearMsgArea
LOCATE 24, 22: COLOR 15, 0
PRINT "Closing "; CHR$(34); "KEYTWO.II"; CHR$(34);
stat = CloseKeyFile(1)
IF stat THEN ShowErrorMsg stat
DelaySec 1
ClearMsgArea
LOCATE 24, 22: COLOR 15, 0
PRINT "Closing "; CHR$(34); "DATA.II"; CHR$(34);
stat = CloseDataFile(0)
IF stat THEN ShowErrorMsg stat
DelaySec 1
COLOR 15, 5: LOCATE 17, 2: PRINT CHR$(251)
END SUB
SUB DoCreateOpenI
COLOR 15, 5: LOCATE 10, 2: PRINT CHR$(16)
ClearMsgArea
LOCATE 24, 22: COLOR 15, 0
IF FileExists("KEYONE.I") THEN KILL "KEYONE.I"
PRINT "Creating and opening "; CHR$(34); "KEYONE.I"; CHR$(34);
stat = CreateKeyFile("KEYONE.I", 9)
IF stat THEN ShowErrorMsg stat
stat = OpenKeyFile("KEYONE.I", 0)
IF stat THEN ShowErrorMsg stat
COLOR 15, 1: LOCATE 2, 29: PRINT "KEYONE.I"
DelaySec 1
COLOR 15, 5: LOCATE 10, 2: PRINT CHR$(251)
END SUB
SUB DoCreateOpenII
row = 4: col = 22: rows = 16: cols = 18
COLOR 15, 5: LOCATE 14, 2: PRINT CHR$(16)
ClearMsgArea
ScrollWindow row, col, rows, cols, 1, 0 '{clear window}
ScrollWindow row, col + 20, rows, cols, 1, 0
ScrollWindow row, col + 40, rows, cols, 1, 0
LOCATE 24, 22: COLOR 15, 0
IF FileExists("KEYONE.II") THEN KILL "KEYONE.II"
PRINT "Creating and opening "; CHR$(34); "KEYONE.II"; CHR$(34);
stat = CreateKeyFile("KEYONE.II", 7)
IF stat THEN ShowErrorMsg stat
stat = OpenKeyFile("KEYONE.II", 0)
IF stat THEN ShowErrorMsg stat
COLOR 15, 1: LOCATE 2, 29: PRINT "KEYONE.II"
DelaySec 1
ClearMsgArea
LOCATE 24, 22: COLOR 15, 0
IF FileExists("KEYTWO.II") THEN KILL "KEYTWO.II"
PRINT "Creating and opening "; CHR$(34); "KEYTWO.II"; CHR$(34);
stat = CreateKeyFile("KEYTWO.II", 8)
IF stat THEN ShowErrorMsg stat
stat = OpenKeyFile("KEYTWO.II", 1)
IF stat THEN ShowErrorMsg stat
COLOR 15, 1: LOCATE 2, 49: PRINT "KEYTWO.II"
DelaySec 1
ClearMsgArea
LOCATE 24, 22: COLOR 15, 0
IF FileExists("DATA.II") THEN KILL "DATA.II"
PRINT "Creating and opening "; CHR$(34); "DATA.II"; CHR$(34);
stat = CreateDataFile("DATA.II", 16)
IF stat THEN ShowErrorMsg stat
stat = OpenDataFile("DATA.II", 0)
IF stat THEN ShowErrorMsg stat
COLOR 15, 1: LOCATE 2, 69: PRINT "DATA.II"
DelaySec 1
COLOR 15, 5: LOCATE 14, 2: PRINT CHR$(251)
END SUB
SUB DoDeleteReadI
row = 4: col = 22: rows = 16: cols = 18
COLOR 15, 5: LOCATE 12, 2: PRINT CHR$(16)
ClearMsgArea
LOCATE 24, 22: COLOR 15, 0
PRINT "Deleting every other key in "; CHR$(34); "KEYONE.I"; CHR$(34);
cnt = 0
prnrow = 3
COLOR 15, 1
stat = RetrieveFirst(0, Qkey$, Qurecno&)
DO WHILE stat = 0
stat = RetrieveNext(0, Qkey$, Qurecno&)
IF stat = 0 THEN stat = DeleteKey(0, Qkey$)
IF stat = 0 THEN stat = RetrieveNext(0, Qkey$, Qurecno&)
LOOP
DelaySec 2
ScrollWindow row, col, rows, cols, 1, 0 '{clear window}
ClearMsgArea
LOCATE 24, 22: COLOR 15, 0
PRINT "Reading the remaining keys from "; CHR$(34); "KEYONE.I"; CHR$(34);
prnrow = 3
COLOR 15, 1
stat = RetrieveFirst(0, Qkey$, Qurecno&)
DO WHILE stat = 0
prnrow = prnrow + 1
IF prnrow > 19 THEN
ScrollWindow row, col, rows, cols, 1, 1
prnrow = 19
END IF
LOCATE prnrow, 23
PRINT Qkey$;
stat = RetrieveNext(0, Qkey$, Qurecno&)
LOOP
DelaySec 2
COLOR 15, 5: LOCATE 12, 2: PRINT CHR$(251)
END SUB
SUB DoDeleteReadII
row = 4: col = 22: rows = 16: cols = 18
COLOR 15, 5: LOCATE 16, 2: PRINT CHR$(16)
ClearMsgArea
LOCATE 24, 22: COLOR 15, 0
PRINT "Deleting every third key in "; CHR$(34); "KEYTWO.II"; CHR$(34); " and its data";
LOCATE 25, 22
PRINT "record in "; CHR$(34); "DATA.II"; CHR$(34);
cnt = 0
prnrow = 3
COLOR 15, 1
stat = GetFirst(1, 0, Qkey$, Qrec$)
DO WHILE stat = 0
stat = GetNext(1, 0, Qkey$, Qrec$)
IF stat = 0 THEN stat = GetNext(1, 0, Qkey$, Qrec$)
IF stat = 0 THEN stat = DeleteKeyRecord(1, 0, Qkey$)
stat = GetNext(1, 0, Qkey$, Qrec$)
LOOP
DelaySec 2
ScrollWindow row, col + 20, rows, cols, 1, 0'{clear window}
ScrollWindow row, col + 40, rows, cols, 1, 0
ClearMsgArea
LOCATE 24, 22: COLOR 15, 0
PRINT "Reading the remaining keys from "; CHR$(34); "KEYTWO.II"; CHR$(34); " and its data";
LOCATE 25, 22
PRINT "from "; CHR$(34); "DATA.II"; CHR$(34); " in REVERSE";
prnrow = 20
COLOR 15, 1
stat = GetLast(1, 0, Qkey$, Qrec$)
DO WHILE stat = 0
prnrow = prnrow - 1
IF prnrow < 4 THEN
ScrollWindow row, col + 20, rows, cols, 1, -1
ScrollWindow row, col + 40, rows, cols, 1, -1
prnrow = 4
END IF
LOCATE prnrow, 43
PRINT Qkey$;
LOCATE prnrow, 63
PRINT Qrec$;
stat = GetPrev(1, 0, Qkey$, Qrec$)
LOOP
DelaySec 3
COLOR 15, 5: LOCATE 16, 2: PRINT CHR$(251)
END SUB
SUB DoDemo
DoInitQBTREE
IF TestI THEN
DoCreateOpenI
DoStoreReadI
DoDeleteReadI
DoCloseI
END IF
IF TestII THEN
DoCreateOpenII
DoAddReadII
DoDeleteReadII
DoCloseII
END IF
END SUB
SUB DoInitQBTREE
COLOR 15, 5: LOCATE 9, 2: PRINT CHR$(16)
ClearMsgArea
LOCATE 24, 22: COLOR 15, 0
PRINT "Allocating buffer areas for 2 key and 1 data file.";
stat = InitQBTREE(2, 1) '{actually, this is 3 key and 2 data!}
IF stat THEN ShowErrorMsg stat
DelaySec 2
COLOR 15, 5: LOCATE 9, 2: PRINT CHR$(251)
END SUB
SUB DoStoreReadI
row = 4: col = 22: rows = 16: cols = 18
COLOR 15, 5: LOCATE 11, 2: PRINT CHR$(16)
ClearMsgArea
LOCATE 24, 22: COLOR 15, 0
PRINT "Storing"; MaxKeys; "rnd 9-byte keys to "; CHR$(34); "KEYONE.I"; CHR$(34);
cnt = 0
prnrow = 3
COLOR 15, 1
DO
keynum$ = CHR$(65 + (RND * 25)) + LTRIM$(STR$(INT(RND * 8999) + 1000)) + LTRIM$(STR$(INT(RND * 8999) + 1000))
stat = StoreKey(0, keynum$, CLNG(cnt))
IF stat = 0 THEN
prnrow = prnrow + 1
IF prnrow > 19 THEN
ScrollWindow row, col, rows, cols, 1, 1
prnrow = 19
END IF
LOCATE prnrow, 23
PRINT keynum$;
cnt = cnt + 1
ELSEIF stat <> 201 THEN
nul = CloseKeyFile(0)
ShowErrorMsg stat
END IF
LOOP UNTIL cnt >= MaxKeys
DelaySec 2
ScrollWindow row, col, rows, cols, 1, 0 '{clear window}
ClearMsgArea
LOCATE 24, 22: COLOR 15, 0
PRINT "Reading the stored keys from "; CHR$(34); "KEYONE.I"; CHR$(34);
prnrow = 3
COLOR 15, 1
stat = RetrieveFirst(0, Qkey$, Qurecno&)
DO WHILE stat = 0
prnrow = prnrow + 1
LOCATE prnrow, 23
IF prnrow > 19 THEN
ScrollWindow row, col, rows, cols, 1, 1
prnrow = 19
LOCATE prnrow, 23
END IF
PRINT Qkey$;
stat = RetrieveNext(0, Qkey$, Qurecno&)
LOOP
DelaySec 2
COLOR 15, 5: LOCATE 11, 2: PRINT CHR$(251)
END SUB
SUB DoTitleScreen
DEF SEG = 0
CRTC = PEEK(&H463)
DEF SEG
IF CRTC = &HD4 THEN VideoSeg = &HB800 ELSE VideoSeg = &HB000
CLS
LOCATE , , 0
row = 1: col = 1: rows = 22: cols = 20: fg = 15: bg = 5
MakeWindow row, col, rows, cols, bg
COLOR fg, bg
title$ = "QBTREE 5.00 DEMO"
LOCATE row + 1, Center(title$, col, cols)
PRINT title$;
PRINT
PRINT " "; STRING$(18, 196)
PRINT
PRINT " About QBTREE"
PRINT
PRINT " "; STRING$(18, 196)
PRINT
PRINT " 1. Init QBTREE"
PRINT " 2. Create/Open I"
PRINT " 3. Store/Read"
PRINT " 4. Delete/Read"
PRINT " 5. Close"
PRINT " 6. Create/Open II"
PRINT " 7. Add/Read"
PRINT " 8. Delete/Read"
PRINT " 9. Close"
PRINT
PRINT
PRINT " "; STRING$(18, 196)
PRINT " (C)1991 by"
PRINT " Cornel Huth"
COLOR 5, 1
PRINT STRING$(20, 223)
PRINT STRING$(20, 223);
LOCATE 25, 1
PRINT STRING$(20, 223);
row = 1: col = 21: rows = 22: cols = 60: fg = 15: bg = 1
COLOR fg
MakeWindow row, col, rows, cols, bg
LOCATE row + 1, 23: PRINT "File:"
LOCATE row + 1, 43: PRINT "File:"
LOCATE row + 1, 63: PRINT "File:"
LOCATE row + 2, 22: PRINT STRING$(17, 196)
LOCATE row + 2, 42: PRINT STRING$(17, 196)
LOCATE row + 2, 62: PRINT STRING$(17, 196)
FOR i = row + 1 TO rows + 2
LOCATE i, 40: PRINT CHR$(179);
LOCATE i, 60: PRINT CHR$(179);
NEXT
LOCATE row + 19, 22: PRINT STRING$(17, 196)
LOCATE row + 19, 42: PRINT STRING$(17, 196)
LOCATE row + 19, 62: PRINT STRING$(17, 196)
COLOR 1, 0
LOCATE 23, 21
PRINT STRING$(60, 223)
row = 24: col = 21: rows = 2: cols = 60: fg = 15: bg = 0
COLOR fg
MakeWindow row, col, rows, cols, bg
COLOR 15, 0
LOCATE 24, 22
drv$ = CHR$(GetDefaultDrive)
PRINT drv$; ": has";
GetDiskInfo drv$, AvailClusters, MaxClusters, BytesSector, SecCluster, freebytes&
PRINT freebytes&; "of"; (1& * MaxClusters * SecCluster * BytesSector); "bytes free using"; BytesSector;
LOCATE , POS(0) - 1
PRINT "-byte";
LOCATE 25, 22
KC = (SecCluster * BytesSector) \ 1024
IF KC >= 1 THEN
PRINT "sectors and"; KC;
LOCATE , POS(0) - 1
ELSE
PRINT "sectors and ½ "; '{HD disks have 1 sector / cluster}
END IF
PRINT "K clusters with";
PRINT AvailClusters; "of"; MaxClusters; "clusters free";
DelaySec 2
akey = SignalMessage("Press <Enter> to begin", 1)
IF akey = 27 THEN
COLOR 7, 0: LOCATE 25, 1: PRINT SPACE$(80);
LOCATE 24, 1
SYSTEM
END IF
END SUB
FUNCTION GetKey (waitfor)
'if waitfor <> 0 then wait until a key is struck
'else check just once - the ASCII code is returned,
'e.g., press A returns 65, a=97...extended keys such
'as the cursor and function keys return the code+1000,
'e.g, press F1 returns 1059, shift-F1=1084...
LOCATE , , 1
DO: LOOP WHILE INKEY$ <> ""
k = 0
DO
k$ = UCASE$(INKEY$)
IF LEN(k$) = 2 THEN
k = 1000 + ASC(RIGHT$(k$, 1))
ELSEIF LEN(k$) = 1 THEN
k = ASC(k$)
END IF
LOOP WHILE k = 0 AND waitfor
GetKey = k
LOCATE , , 0
END FUNCTION
SUB GetWindow (row, col, rows, cols)
'assume a standard 80-column text mode
IF rows > 25 OR cols > 80 THEN STOP
BuffSeg = VARSEG(WinBuff(0)): BuffOff = VARPTR(WinBuff(0))
row0 = row - 1
row1 = row0 + rows - 1
col0 = col - 1
col1 = col0 + cols - 1
skipbytes = (col0 + (79 - col1)) * 2
vaddr = row0 * 160 + (col0 * 2)
baddr = BuffOff
DEF SEG = BuffSeg
POKE baddr, rows
POKE baddr + 1, cols
baddr = baddr + 2
FOR i = row0 TO row1
FOR j = col0 TO col1
DEF SEG = VideoSeg
byte1 = PEEK(vaddr)
byte2 = PEEK(vaddr + 1)
vaddr = vaddr + 2
DEF SEG = BuffSeg
POKE baddr, byte1
POKE baddr + 1, byte2
baddr = baddr + 2
NEXT
vaddr = vaddr + skipbytes
NEXT
DEF SEG
END SUB
SUB MakeWindow (row, col, rows, cols, bg)
'changes fg color to black so we exit with fg=15
COLOR 0, bg
IF bg <> 7 THEN
FOR i = row TO (row + rows - 1)
LOCATE i, col
PRINT SPACE$(cols);
NEXT
ELSE
LOCATE row, col
PRINT SPACE$(cols);
FOR i = row + 1 TO (row + rows - 1)
LOCATE i, col
PRINT SPACE$(1);
LOCATE i, (col + cols - 1)
PRINT SPACE$(1);
NEXT
LOCATE , col
PRINT SPACE$(cols);
END IF
COLOR 15
END SUB
SUB PutWindow (row, col)
'assume a standard 80-column text mode
BuffSeg = VARSEG(WinBuff(0)): BuffOff = VARPTR(WinBuff(0))
baddr = BuffOff
DEF SEG = BuffSeg
rows = PEEK(baddr)
cols = PEEK(baddr + 1)
baddr = baddr + 2
row0 = row - 1
row1 = row0 + rows - 1
col0 = col - 1
col1 = col0 + cols - 1
skipbytes = (col0 + (79 - col1)) * 2
vaddr = row0 * 160 + (col0 * 2)
FOR i = row0 TO row1
FOR j = col0 TO col1
DEF SEG = BuffSeg
byte1 = PEEK(baddr)
byte2 = PEEK(baddr + 1)
baddr = baddr + 2
DEF SEG = VideoSeg
POKE vaddr, byte1
POKE vaddr + 1, byte2
vaddr = vaddr + 2
NEXT
vaddr = vaddr + skipbytes
NEXT
DEF SEG
END SUB
SUB ScrollWindow (row, col, rows, cols, lines, dir)
row0 = row - 1
row1 = row0 + rows - 1
col0 = col - 1
col1 = col0 + cols - 1
attr = SCREEN(row, col, 1)
IF dir > 0 THEN
iregx.ax = &H6 * 256 + lines 'scroll contents up
attr = SCREEN(row1, col, 1)
ELSEIF dir < 0 THEN
iregx.ax = &H7 * 256 + lines 'down
ELSE
iregx.ax = &H600 'clr window
END IF
iregx.bx = attr * 256
iregx.cx = row0 * 256 + col0
iregx.dx = row1 * 256 + col1
VECTORX &H10, iregx, oregx
END SUB
SUB ShowErrorMsg (stat)
COLOR 15, 0: LOCATE 25, 22
PRINT "QBTREE error:"; stat;
BEEP
DelaySec 4
PRINT
LOCATE , 22
PRINT "This demo has met with fatal error"; stat; "and is quitting."
PRINT
SYSTEM
END SUB
FUNCTION SignalMessage (msg$, waitfor)
row = 10: col = 40 - (LEN(msg$) \ 2): rows = 5: cols = LEN(msg$) + 6
GetWindow row, col, rows, cols
MakeWindow row, col, rows, cols, 7
MakeWindow row + 1, col + 1, rows - 2, cols - 2, 0
LOCATE row + 2, Center(msg$, col, cols)
COLOR 15, 0
PRINT msg$;
SignalMessage = GetKey(waitfor)
PutWindow row, col
END FUNCTION